#ifndef _ENTITY3D_H_
#define _ENTITY3D_H_

#include "engine.h"
#include "opengl/opengl_shader.h"
#include "opengl/opengl_buffer.h"
#include "opengl/opengl_texture.h"
#include "entity/object3D.h"

namespace engine
{

    class Entity3D : public Object3D
    {
    public:
        typedef std::shared_ptr<Entity3D> ptr;

    public:
        bool isRender = true;
        glm::vec3 Color;

    public:
        Entity3D(std::string name, Shader *shader, Texture2D *texture) : vertexSize(0), Color(glm::vec3(1.0f, 1.0f, 1.0f))
        {
            this->name = name;
            this->vertexArray = new VertexArray();
            this->m_pShader = shader;
            this->m_pTexture2D = texture;
        }
        ~Entity3D()
        {
            delete this->vertexArray;
        }

        void render()
        {
            this->m_pShader->use();
            this->m_pTexture2D->bind();
            this->m_pShader->setVector3f("color", this->Color);
            this->m_pShader->setMatrix4("model", this->getTransformMatrix());
            vertexArray->bind();
            glDrawArrays(this->primitiveType, 0, vertexSize);
            // glDrawElements(primitiveType, 6, GL_UNSIGNED_INT, 0);
        }

        void setColor(float r, float g, float b)
        {
            this->Color.x = r;
            this->Color.y = g;
            this->Color.z = b;
        }

    protected:
        VertexArray *vertexArray;            //顶点数组
        GLsizei vertexSize;                  //顶点数量
        GLenum primitiveType = GL_TRIANGLES; //图元类型

        // void drawVertex();
        // virtual void createBuffer();

        // bool _isVisible, _useColor;

        // Material::ptr _material;
        // bool _receiveShadow;

        // Box3D _bbx;
        // Sphere3D _sphere;

        // VertexData::ptr _vertex_data;
        // IndexData::ptr _index_data;

        // bool _vertexChanged;
        // bool _bufferCreated;

    private:
        Shader *m_pShader;
        Texture2D *m_pTexture2D;
    };

}
#endif